<template>
  <a-modal
    title="修改收费项目"
    :width="640"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          label="名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input v-decorator="['name', {initialValue:allsaveData.name,rules: [{required: true, message: '请输入名称'}]}]" />
        </a-form-item>
        <a-form-item
          label="优惠内容"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input v-decorator="['content', {initialValue:allsaveData.content,rules: [{required: true, message: '请输入优惠内容'}]}]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { saveDiscount } from '@/api/manage'
import { mapGetters } from 'vuex'
export default {
  data () {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      },
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this),
      type: 1,
      tokened: '',
      ar_id: '',
      cm_mg_id: '',
      allsaveData: [],
      selcedDef: ''
    }
  },
  methods: {
    ...mapGetters(['token', 'pmsArId', 'nowMg']),
    go (data) {
      this.visible = true
      this.tokened = this.token()
      this.ar_id = this.pmsArId()
      this.cm_mg_id = this.nowMg()
      this.allsaveData = data
    },
    handleSubmit () {
      const { form: { validateFields } } = this
      this.confirmLoading = true
      validateFields((errors, values) => {
        if (!errors) {
          values.pms_ar_id = this.ar_id
          values.cm_message_id = this.cm_mg_id
          values.id = this.allsaveData.id
          const savedate = {
            token: this.tokened, ar_id: this.ar_id, cm_mg_id: this.cm_mg_id, saveData: values
          }
          saveDiscount(savedate).then(res => {
            this.visible = false
            this.confirmLoading = false
            this.$emit('ok', values)
          })
        } else {
          this.confirmLoading = false
        }
      })
    },
    handleCancel () {
      this.visible = false
    }
  }
}
</script>
